package com.ymtms.arrivalofgoods.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.netflix.discovery.converters.Auto;
import com.ymtms.arrivalofgoods.constant.SmsConstants;
import com.ymtms.arrivalofgoods.dao.CallbackInformationMapper;
import com.ymtms.arrivalofgoods.dao.DeliveryGoodsMapper;
import com.ymtms.arrivalofgoods.dao.GoodsbillMasterMapper;
import com.ymtms.arrivalofgoods.dao.GoodsbillReceoptMainMapper;
import com.ymtms.arrivalofgoods.pojo.CallbackInformation;
import com.ymtms.arrivalofgoods.pojo.DeliveryGoods;
import com.ymtms.arrivalofgoods.pojo.GoodsbillMaster;
import com.ymtms.arrivalofgoods.pojo.GoodsbillReceoptMain;
import com.ymtms.arrivalofgoods.utils.CommonUtils;
import com.ymtms.arrivalofgoods.utils.Smsutil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class ArriveNotifyServiceImpl {

    @Autowired
    private GoodsbillReceoptMainMapper goodsbillReceoptMainMapper;
    @Autowired
    private CallbackInformationMapper callbackInformationMapper;
    @Autowired
    private GoodsbillMasterMapper goodsbillMasterMapper;

    /**
     * Discription Todo通知客户货物已提
     *
     * @return
     * @Param num ，回执单主ID
     * @author Administrator
     * @date 2019/10/26 15:54
     **/
    public void notifyCustomer(Integer num) {

    try {
        GoodsbillReceoptMain goodsbillReceoptMain = goodsbillReceoptMainMapper.selectByPrimaryKey(num);

        GoodsbillMaster goodsbillMaster = goodsbillMasterMapper.selectByPrimaryKey(goodsbillReceoptMain.getGoodsBillpkid());

        String phone = goodsbillMaster.getSendGoodsCustomerTel();
        //System.out.println(phone);
        //动态取货码
        String code = SmsConstants.getCode();

           String myPhone="13308233567";
        String sms=      "SMS_176520949";
            //短信通知客户取货
            JSONObject modelParam = new JSONObject();
            modelParam.put("code", code);
            Smsutil.sendSms(SmsConstants.smsAppKey, SmsConstants.smsSerect, SmsConstants.smsSign, sms, myPhone, modelParam);
            //生成回告信息

            CallbackInformation callbackInformation = new CallbackInformation();
            callbackInformation.setDialNo(phone);
            callbackInformation.setType("提货");
            callbackInformation.setContent("请凭验证码：" + code + "到指定处取货物，有效时间24小时，请勿泄露给他人!!!!");
            callbackInformation.setWriteTime(new Date());
            callbackInformation.setWriter("接货员");
            callbackInformation.setFinallyDialTime(new Date());
            callbackInformation.setSuccess(1);
            callbackInformation.setLocked(0);
            callbackInformation.setBillId(goodsbillMaster.getGoodsBillCode());
            callbackInformation.setBillType("到货单");
            callbackInformation.setCount(1);
            callbackInformationMapper.insertSelective(callbackInformation);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
